sysroot: Drop unnecessary `dup()` invocation
authorColin Walters <walters@verbum.org>
Sat, 27 Aug 2016 12:50:47 +0000 (08:50 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Sun, 28 Aug 2016 13:56:03 +0000 (13:56 +0000)
It's close-on-exec, not close-on-fork.  I was clearly confused when
writing this; it works just fine to reference the fd in the child and
`fchdir()` before exec.  So drop the unnecessary duplication.

Just noticed this while reading the code for a random other reason.

Closes: #473
Approved by: giuseppe

src/libostree/ostree-sysroot.c

index 2a55c6b15616946b955fbea075c44a62fff5ba66..227fdd24675640522faef2ce540588a185c11fc5 100644 (file)
@@ -1776,17 +1776,6 @@ ostree_sysroot_deployment_unlock (OstreeSysroot     *self,
    * threads, etc.
    */
   {
-    /* Make a copy of the fd that's *not* FD_CLOEXEC so that we pass
-     * it to the child.
-     */
-    glnx_fd_close int child_deployment_dfd = dup (deployment_dfd);
-
-    if (child_deployment_dfd < 0)
-      {
-        glnx_set_error_from_errno (error);
-        goto out;
-      }
-
     mount_child = fork ();
     if (mount_child < 0)
       {
@@ -1796,9 +1785,8 @@ ostree_sysroot_deployment_unlock (OstreeSysroot     *self,
     else if (mount_child == 0)
       {
         /* Child process.  Do NOT use any GLib API here. */
-        if (fchdir (child_deployment_dfd) < 0)
+        if (fchdir (deployment_dfd) < 0)
           exit (EXIT_FAILURE);
-        (void) close (child_deployment_dfd);
         if (mount ("overlay", "/usr", "overlay", 0, ovl_options) < 0)
           exit (EXIT_FAILURE);
         exit (EXIT_SUCCESS);